function Get-StatTermStore
{
    <# 
        .SYNOPSIS
            Returns a globally scoped managed metadata term store for the specified managed metadata service application.

        .DESCRIPTION
            Part of the SharePoint Total Automation Toolkit (STAT). This function returns a globally scoped managed metadata term store for the specified managed metadata service application..
            
        .EXAMPLE
            Get-StatGlobalTermStore -ManagedMetadataServiceAppName 'Contoso Managed Metadata Service'

        .EXAMPLE
            $serviceAppName | Get-StatGlobalTermStore

        .PARAMETER ManagedMetadataServiceAppProxyName
            The name of the Managed Metadata Service Application from which to get the global term store
            (e.g. 'Contoso Managed Metadata Service')

        .OUTPUTS
    		Microsoft.SharePoint.Taxonomy.TermStore
    #>
    [CmdletBinding(DefaultParametersetName="Default")]
    param([parameter(ParameterSetName = "Default", 
                     Mandatory = $true,
                     ValueFromPipeline=$true,
                     ValueFromPipelineByPropertyName=$true, 
                     HelpMessage = "The name of the Managed Metadata Service Application from which to get the term store")]
                     [string]$ManagedMetadataServiceAppProxyName,
          [parameter(ParameterSetName = "Default", 
                     Mandatory = $false,
                     HelpMessage = "The name of the site collection from which to get the term store. If none is provided, the global term store will be returned.")]
                     [string]$SiteCollectionUrl)

    $taxonomySession = Get-StatSPTaxonomySession -SiteCollectionUrl $SiteCollectionUrl
    
    $termStore = $taxonomySession.TermStores[$ManagedMetadataServiceAppProxyName]
    
    return $termStore;
}